package org.example.struct.array2;

/**
 * @author liyishan
 * @date 2023/10/16 09:51
 * @apiNote
 */

public class Test00718FindLength {

    public static void main(String[] args) {
        int[] nums1 = new int[]{1,2,3,2,1};
        int[] nums2 = new int[]{3,2,1,4,7};
        int count = test(nums1, nums2);
        System.out.println(count);

    }
    public static int test(int[] nums1, int[] nums2) {
        int n =nums1.length,m = nums2.length;
        int[][] dp = new int[n+1][m+1];
        int ans = 0;
        for(int i =n-1; i >=0; i--){
            for(int j =m-1; j >=0; j--){
                dp[i][j] = nums1[i] == nums2[j] ? dp[i+1][j+1] + 1 : 0;
                ans = Math.max(ans, dp[i][j]);
            }
        }
        return ans;
    }
}
